'use strict';

module.exports = app => {
  const { STRING, INTEGER, TEXT, DECIMAL, DATE } = app.Sequelize;

  const Review = app.model.define('review', {
    reviewId: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
      field: 'review_id',
      comment: '评价编号'
    },
    enterpriseId: {
      type: INTEGER,
      allowNull: false,
      field: 'enterprise_id',
      comment: '企业编号'
    },
    userId: {
      type: INTEGER,
      allowNull: false,
      field: 'user_id',
      comment: '用户编号'
    },
    content: {
      type: TEXT,
      allowNull: false,
      comment: '评价内容'
    },
    rating: {
      type: DECIMAL(3, 2),
      allowNull: false,
      comment: '评分'
    },
    reviewTime: {
      type: DATE,
      allowNull: false,
      field: 'review_time',
      defaultValue: app.Sequelize.NOW,
      comment: '评价时间'
    },
    replyContent: {
      type: TEXT,
      allowNull: true,
      field: 'reply_content',
      comment: '企业回复内容'
    },
    replyTime: {
      type: DATE,
      allowNull: true,
      field: 'reply_time',
      comment: '回复时间'
    },
    complaintStatus: {
      type: STRING(20),
      allowNull: false,
      defaultValue: 'none',
      field: 'complaint_status',
      comment: '投诉状态：none-无投诉，pending-待处理，processed-已处理'
    },
    userName: {
      type: STRING(50),
      allowNull: true,
      field: 'user_name',
      comment: '用户姓名'
    }
  }, {
    tableName: 'review',
    timestamps: false,
    comment: '用户评价表'
  });

  // 定义关联关系
  Review.associate = function() {
    // 评价属于企业
    app.model.Review.belongsTo(app.model.Enterprise, {
      foreignKey: 'enterpriseId',
      targetKey: 'enterpriseId',
      as: 'enterprise'
    });
  };

  return Review;
};











































